
package View;

import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 *
 * @author CCD gruppe 2
 */
public class UserlistFrame extends javax.swing.JFrame {


    private javax.swing.JButton closeButton;
    private javax.swing.JButton editUserButton;
    private javax.swing.JLabel expertiseLabel;
    private javax.swing.JTextArea expertiseTextArea;
    private javax.swing.JTextArea workplaceTextArea;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel userNameLabel;
    private javax.swing.JTextField userNameTextField;
    private javax.swing.JList userlistJList;
    private javax.swing.JLabel usersLabel;
    private javax.swing.JLabel workplaceLabel;
    DefaultListModel userlistModel;
    private int selectedIndex;
    private String selectedUsername;

    /** Creates new form UserlistFrame */
    public UserlistFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        usersLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        userlistJList = new javax.swing.JList();
        jSeparator1 = new javax.swing.JSeparator();
        userNameLabel = new javax.swing.JLabel();
        userNameTextField = new javax.swing.JTextField();
        expertiseLabel = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        expertiseTextArea = new javax.swing.JTextArea();
        workplaceLabel = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        workplaceTextArea = new javax.swing.JTextArea();
        editUserButton = new javax.swing.JButton();
        closeButton = new javax.swing.JButton();
        userlistModel = new DefaultListModel();

        userlistJList.setModel(userlistModel);

        usersLabel.setText("Brukere:");

        userlistJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(userlistJList);

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        userNameLabel.setText("Navn:");

        expertiseLabel.setText("Ekspertise:");

        expertiseTextArea.setColumns(20);
        expertiseTextArea.setRows(5);
        jScrollPane2.setViewportView(expertiseTextArea);

        workplaceLabel.setText("Arbeidsplass:");

        workplaceTextArea.setColumns(20);
        workplaceTextArea.setRows(5);
        jScrollPane3.setViewportView(workplaceTextArea);

        editUserButton.setText("Rediger");

        closeButton.setText("Lukk");

        userNameTextField.setFocusable(false);
        expertiseTextArea.setFocusable(false);
        workplaceTextArea.setFocusable(false);


        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(usersLabel)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 205, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(editUserButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(closeButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 97, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(userNameLabel)
                    .add(expertiseLabel)
                    .add(jScrollPane2)
                    .add(userNameTextField)
                    .add(workplaceLabel)
                    .add(jScrollPane3))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .add(usersLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 259, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .addContainerGap()
                        .add(userNameLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(userNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(expertiseLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(workplaceLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(closeButton)
                    .add(editUserButton))
                .addContainerGap())
        );
        pack();
        setCenterPos(this);
        setVisible(false);

    }// </editor-fold>

    private static void setCenterPos(JFrame frame) {
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (int) ((screen.getWidth() - frame.getWidth()) / 2);
        int y = (int) ((screen.getHeight() - frame.getHeight()) / 2);
        frame.setLocation(x, y);
    }

    /**
     * A method that sets gui elements to focusable.
     */
    public void editButtonClicked(){
        userNameTextField.setFocusable(true);
        expertiseTextArea.setFocusable(true);
        workplaceTextArea.setFocusable(true);
        userlistJList.setEnabled(false);
        editUserButton.setText("Lagre");
    }

    /**
     * A method that sets the userinfo text and makes the non-focusable.
     * @param username
     * @param workplace
     * @param expertise
     */
    public void saveButtonClicked(String username, String workplace, String expertise) {
        userNameTextField.setFocusable(false);
        expertiseTextArea.setFocusable(false);
        workplaceTextArea.setFocusable(false);
        userNameTextField.setText(username);
        expertiseTextArea.setText(expertise);
        workplaceTextArea.setText(workplace);
        userlistJList.setEnabled(true);
        editUserButton.setText("Rediger");
    }

    /*
     * Getters and setters
     */
    public JButton getCloseButton() {
        return closeButton;
    }

    public JButton getEditUserButton() {
        return editUserButton;
    }

    public JLabel getExpertiseLabel() {
        return expertiseLabel;
    }

    public JTextArea getExpertiseTextArea() {
        return expertiseTextArea;
    }

    public JTextArea getWorkplaceTextArea() {
        return workplaceTextArea;
    }

    public JScrollPane getjScrollPane1() {
        return jScrollPane1;
    }

    public JScrollPane getjScrollPane2() {
        return jScrollPane2;
    }

    public JScrollPane getjScrollPane3() {
        return jScrollPane3;
    }

    public JSeparator getjSeparator1() {
        return jSeparator1;
    }

    public JLabel getUserNameLabel() {
        return userNameLabel;
    }

    public JTextField getUserNameTextField() {
        return userNameTextField;
    }

    public JList getUserlistJList() {
        return userlistJList;
    }

    public JLabel getUsersLabel() {
        return usersLabel;
    }

    public JLabel getWorkplaceLabel() {
        return workplaceLabel;
    }

    public DefaultListModel getUserlistModel() {
        return userlistModel;
    }

    public int getSelectedIndex() {
        return selectedIndex;
    }

    public void setSelectedIndex(int selectedIndex) {
        this.selectedIndex = selectedIndex;
    }

    public String getSelectedUsername(){
        return selectedUsername;
    }

    public void setSelectedUsername(String username){
        this.selectedUsername = username;
    }


    public void setSelectedIndexUserList(int index){
        userlistJList.setSelectedIndex(index);
    }


}
